package com.abl.app.controller.user;

import com.abl.core.common.util.AuthKit;
import com.abl.core.domain.db.SysUser;
import com.abl.core.domain.project.SRS;
import com.abl.core.domain.project.TokenVO;
import com.abl.core.domain.wx.WxtMpLoginParam;
import com.abl.core.service.mt.MtRoomService;
import com.abl.core.service.sys.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 移动端个人设置接口
 */
@RestController
@RequestMapping("/app/user")
public class UserC {
    @Resource
    private SysUserService sysUserService;

    @Resource
    private MtRoomService mtRoomService;

    //APP登录
    @PostMapping("/appLogin")
    public SRS<TokenVO> appLogin(String phoneMobile, String password) {
        TokenVO tokenVO = sysUserService.appLogin(phoneMobile, password);
        //判断并创建会议室
        //        boolean a = mtRoomService.createMtRoom(phoneMobile);
        return SRS.bySuccess(tokenVO);
    }

    //微信一键登录
    @PostMapping("/wxMpNoPhoneLogin")
    public SRS<TokenVO> wxMpNoPhoneLogin(WxtMpLoginParam wxtMpLoginParam) {
        TokenVO tokenVO = sysUserService.wxMpNoPhoneLogin(wxtMpLoginParam);
        return SRS.bySuccess(tokenVO);
    }

    @PostMapping("/updateUserInfo")
    public SRS<SysUser> updateUserInfo(SysUser param) {
        param.setId(AuthKit.mastLogin().getUserId());
        return SRS.bySuccess(sysUserService.updateUserInfo(param));
    }

//    @PostMapping("/updateUserSetting")
//    public SRS<Object> updateUserSetting(SysUser param) {
//        return SRS.bySuccess();
//    }

    //读取绿添小程序信息
//    @PostMapping("/selectLtMpInfo")
//    public SRS<JSONObject> selectLtMpInfo(String type) {
//        JSONObject jsonObject = sysUserService.selectLtMpInfo(type);
//        return SRS.bySuccess(jsonObject);
//    }

    //刷新Token
    @PostMapping("/refreshToken")
    public SRS<TokenVO> refreshToken(String refreshToken) {
        TokenVO tokenVO = sysUserService.refreshToken(refreshToken);
        return SRS.bySuccess(tokenVO);
    }

    //查询个人信息
    @PostMapping("/userInfo")
    public SRS<SysUser> userInfo() {
        SysUser sysUser = sysUserService.appUserInfo();
        return SRS.bySuccess(sysUser);
    }

}
